﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETL.Business.Models;
using ETL.DataAccess;
using ETL.Entity;
using ETL.Common.Logging;

namespace ETL.Business.Handlers.ProjectEngineerHandler
{
    public class GetOtherEngineers
    {
        private readonly ProjectEngineerRepository _projectEngineerRepository;

        public GetOtherEngineers()
        {
            _projectEngineerRepository = new ProjectEngineerRepository();
        }

        public GetOtherEngineers(ProjectEngineerRepository projectEngineerRepository)
        {
            _projectEngineerRepository = projectEngineerRepository;
        }

        public virtual IEnumerable<ProjectEngineerModel> Execute(int? projectId, string currentUser)
        {
            IEnumerable<SCHEDULED_RESOURCE_USAGES> engineersData = null;

            //get from db
            try
            {
                engineersData = _projectEngineerRepository.GetOtherEngineers(projectId, currentUser);
            }
            catch (Exception ex)
            {
                LogService.Service.Debug(ex);
            }

            var engineersModel = from e in engineersData
                                 select new ProjectEngineerModel(e);

            return engineersModel;
        }
    }
}
